// pages/doctor-course-payEnd/doctor-course-payEnd.js
const app= getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderid:'',
    beautyCoin:'',
    payType:''       // 1 商品进来
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderid: options.orderid,
      beautyCoin: options.beautyCoin,
      payType: options.payType
    })
  },
  
  pay(){
    if (this.data.payType == 1){
      const param = {
        orderid: this.data.orderid
      };
      app.request({
        url: "shopp/payment/balancePayment",
        data: param,
        success: function (res) {
          if (res.status_code == 200) {
            app.showToast("支付成功")
            setTimeout(() => {
              wx.reLaunch({
                url: '../doctor-index/doctor-index'
              })
            }, 1500)
          }
        },
        fail: function (res) {}
      });
    }else{
      const param = {
        orderId: this.data.orderid,
        beautyCoin: this.data.beautyCoin
      };
      app.request({
        url: "train/course/payCourseByBeautyCoin",
        data: param,
        success: function (res) {
          if(res.status_code == 200){
            app.showToast("支付成功")
            setTimeout(() => {
              wx.navigateTo({
                url: '../doctor-train/doctor-train'
              }
            )}, 1500)
          }
        },
        fail: function (res) {
          // app.requestFail(res);
        }
      });
    }
  }
})